package com.jiazhong.example.project.shoppingcart.mapper;

import com.jiazhong.example.project.shoppingcart.bean.Users;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface UsersMapper {

    @Insert("insert into users values(null,#{username},md5(#{password}),#{phone},now(),1)")
    int save(Users users);

    @Select("select count(0) from users where state=1 and username=#{username}")
    int checkUsername(String username);

    @Select("select count(0) from users where state=1 and phone=#{phone}")
    int checkPhone(String phone);

    @Select("select * from users where state=1 and (username=#{first} or phone=#{first}) and `password`=md5(#{password})")
    Users login(@Param("first") String first, @Param("password") String password);
}
